local skel = fk.CreateSkill{--定义
  name = "kqf__zonggu",
}

Fk:loadTranslationTable{--翻译
  ["kqf__zonggu"] = "纵蛊",
  [":kqf__zonggu"] = "当你受到伤害后，你可以分配弃牌堆中共计两张【杀】或【闪】；这些牌在不可被使用时视为【毒】。",

  ["#kqf__beimihu_askcard"] = "为 %src 分配一张弃牌堆中的牌",
  ["#kqf__beimihu_askplayer"] = "纵蛊：你可以分配弃牌堆中共计两张【杀】或【闪】；这些牌在不可被使用时视为【毒】",

  ["$kqf__zonggu1"] = "让我支配你的命运。",
  ["$kqf__zonggu2"] = "平静的迎接死亡吧。",
  ["@@kqf__beimihu_du-inarea"]= "纵蛊-毒",
}

skel:addEffect(fk.Damaged, {
  can_trigger = function(self, event, target, player, data)
    if not (player:hasSkill(skel.name) and target == player)then return end 
    local room = player.room
    local cards = table.filter(room.discard_pile, function (id)
      return (Fk:getCardById(id).trueName == "jink") or (Fk:getCardById(id).trueName == "slash")
    end)
    if #cards >= 2 then return true end
  end,

  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 2,
      targets = room:getAlivePlayers(),
      skill_name = skel.name, 
      prompt = "#kqf__beimihu_askplayer",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = event:getCostData(self).tos
    --如果只选了一人，则需重复两次
    if #targets == 1 then
      targets[2] = targets[1]
    end
    for _, p in ipairs(targets) do
      local list = {}
      local card1 = player.room:getCardsFromPileByRule("slash", 1, "discardPile")--从弃牌堆选一张杀
      if #card1 > 0 then
        table.insert(list,"slash")--有的话就加入选项
      end
      local card2 = player.room:getCardsFromPileByRule("jink", 1, "discardPile")--从弃牌堆选一张闪
      if #card2 > 0 then
        table.insert(list,"jink")--有的话就加入选项
      end
      local choice = room:askToChoice(player, {
        choices = list,
        skill_name = skel.name,
        cancelable = false,
        prompt = "#kqf__beimihu_askcard:" .. p.id,
      })
      if choice == "slash" then
        --给杀
        room:moveCardTo(card1, Card.PlayerHand, p, fk.ReasonJustMove, skel.name, nil, true, player,"@@kqf__beimihu_du-inarea")
      else
        --给闪
        room:moveCardTo(card2, Card.PlayerHand, p, fk.ReasonJustMove, skel.name, nil, true, player,"@@kqf__beimihu_du-inarea")
      end
      --
    end
  end,
})

--实际是毒的失去代码复制过来的
skel:addEffect(fk.BeforeCardsMove, {
  global = true,
  can_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from == player then
        return true
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from == player and move.skillName ~= skel.name and move.moveReason ~= fk.ReasonUse then
      -- 玩家失去               不为本技能移动牌（无意义          不为使用牌
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand and
          --从手牌失去
            (move.moveVisible or table.contains({Card.PlayerEquip, Card.Processing, Card.DiscardPile}, move.toArea)) then
          --可见的失去
            local card = Fk:getCardById(info.cardId, false)
            if card:getMark("@@kqf__beimihu_du-inarea") > 0 then
            --有标记
              move.extra_data = move.extra_data or {}
              local dat = move.extra_data.poison or {}
              table.insert(dat, player.id)
              move.extra_data.poison = dat
            end
          end
        end
      end
    end
  end,
})
--仅将此牌视为毒，然后用毒的代码结算失去体力，这里无需重复

--禁打出
skel:addEffect("prohibit", {
  prohibit_response = function(self, player, card)
    local subcards = card:isVirtual() and card.subcards or {card.id}
    return #subcards > 0 and table.find(subcards, function(id)
      return Fk:getCardById(id):getMark("@@kqf__beimihu_du-inarea") > 0
    end)
  end,
})


return skel